<template>
  <div class="login-container">
    <!-- 左边 -->
    <div class="logo" />
    <!-- 右边 -->
    <div class="form">
      <h1>智慧园区-登录</h1>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginRef" :model="loginForm" :rules="loginRules">
          <el-form-item prop="username">
            账号
            <br>
            <el-input v-model="loginForm.username" placeholder="请输入手机号" />
          </el-form-item>
          <el-form-item prop="password">
            密码
            <br>
            <el-input v-model="loginForm.password" placeholder="请输入密码" type="password" show-password />
          </el-form-item>
          <el-form-item prop="password">
            模型uuid
            <br>
            <el-input v-model="loginForm.modelUU" type="password" show-password />
          </el-form-item>
          <el-form-item prop="isAgree">
            <el-checkbox v-model="loginForm.isAgree">记住我</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button style="width:350px" type="primary" @click="getLogin">登录</el-button>
          </el-form-item>
          <el-form-item style="width:350px">
            <p style="color: red;">仅用于IT培训教学使用，为保障您的个人信息安全，请勿像平台录入任何个人敏感信息（如手机号，身份证等）！</p>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: 'demo',
        password: 'Hmzs%001',
        isAgree: false,
        modelUU: '66ea8d2a-7416-4be5-ba7e-c030cf88b3f3'
      },
      loginRules: {
        username: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '密码长度应该为6-16位之间', trigger: 'blur' }
        ],
        isAgree: [
          {
            validator: (rule, value, callback) => {
              // rule规则
              // value检查的数据 true/false
              // callback 函数 执行这个函数
              // 成功执行callback 失败也执行callback(错误对象 new Error(错误信息))
              value ? callback() : callback('没有勾选用户平台协议')
            }
          }
        ]
      }
    }
  },
  created() {},
  methods: {
    async getLogin() {
      await this.$refs.loginRef.validate()
      this.$store.dispatch('login/getUserInfo', {
        username: this.loginForm.username,
        password: this.loginForm.password
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container{
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url('~@/assets/login-bg.svg') no-repeat center / cover;
    border-top-right-radius: 60px;
  }
  .form {
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 176px;

    .el-card {
      border: none;
      padding: 0;
    }

    h1 {
      padding-left: 20px;
      font-size: 24px;
    }

   ::v-deep .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }

    ::v-deep .el-checkbox {
      color: #606266;
    }
  }
}
</style>
